package cn.uway.netty.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

public class ServerChannelHandler extends ChannelInitializer<SocketChannel>{
	
    @Override  
    protected void initChannel(SocketChannel ch) throws Exception {  
    	//使用netty的LineBasedFrameDecoder和StringDecoder解决TCP粘包问题（两个不同的请求被合并到了一起）
        ch.pipeline().addLast(new LineBasedFrameDecoder(1024*1024*1024));         
        ch.pipeline().addLast(new StringDecoder());  
           
        ch.pipeline().addLast(new ServerHandler()); 
        ch.config().setAllowHalfClosure(true); //捕获远程主机强制关闭一个连接异常
    } 
    

}
